
#ifndef _CLOG_H_
#define _CLOG_H_

#include <stdbool.h>

#ifdef __cplusplus
extern "C"
{
#endif


#define MAX_BUF (1 * 1024)
#define MAX_FILE_LEN (4 * 1024 * 1024)

    typedef enum _LOG_LEVEL
    {
        EM_LOG_FATAL = 0,
        EM_LOG_ERROR,
        EM_LOG_WARN,
        EM_LOG_INFO,
        EM_LOG_DEBUG,
        EM_LOG_TRACE
    } EM_LOG_LEVEL;

    /**
     * 初始化日志模块，设置日志输出文件
     */
    int clog_init(char *path);
    /**
     * 设置日志文件的最大值
     */
    void clog_set_log_size(int max_size);
    /**
     * 设置日志输出等级
     */
    void clog_set_log_level(int log_level);
    /**
     * 设置是否输出到控制台
     */
    void clog_set_log_stdout(bool en);
    /**
     * 设置是否输出到文件
     */
    void clog_set_log_fileout(bool en);
    /**
     * 退出日志打印
    */
    void clog_exit(void);
    void clog_log(int level, const char *func, int line, const char *fmt, ...);
    void clog_dlog(int level, const char *fmt, ...);
#define EM_LOG(level, fmt, args...) clog_log(level, __func__, __LINE__, fmt, ##args)

#define CMARK(fmt, args...)                                   \
    do                                                           \
    {                                                            \
        clog_log(EM_LOG_TRACE, __func__, __LINE__, fmt, ##args); \
    } while (0)
#define clogt(fmt, args...)                                      \
    do                                                           \
    {                                                            \
        clog_log(EM_LOG_TRACE, __func__, __LINE__, fmt, ##args); \
    } while (0)
#define clogd(fmt, args...)                                      \
    do                                                           \
    {                                                            \
        clog_log(EM_LOG_DEBUG, __func__, __LINE__, fmt, ##args); \
    } while (0)
#define cdlogd(fmt, args...)                                      \
    do                                                           \
    {                                                            \
        clog_dlog(EM_LOG_DEBUG, fmt, ##args); \
    } while (0)
#define clogi(fmt, args...)                                     \
    do                                                          \
    {                                                           \
        clog_log(EM_LOG_INFO, __func__, __LINE__, fmt, ##args); \
    } while (0)

#define clogw(fmt, args...)                                     \
    do                                                          \
    {                                                           \
        clog_log(EM_LOG_WARN, __func__, __LINE__, fmt, ##args); \
    } while (0)

#define cloge(fmt, args...)                                      \
    do                                                           \
    {                                                            \
        clog_log(EM_LOG_ERROR, __func__, __LINE__, fmt, ##args); \
    } while (0)

#define clogf(fmt, args...)                                      \
    do                                                           \
    {                                                            \
        clog_log(EM_LOG_FATAL, __func__, __LINE__, fmt, ##args); \
    } while (0)

void clog_hex(char *msg, unsigned char *bin_data,unsigned short bin_len);
#ifdef __cplusplus
}
#endif

#endif // CLOG_H_
